package com.hbm.usercenter.factory;

import android.support.v4.util.SparseArrayCompat;

import com.hbm.usercenter.base.BaseFragment;


public class FragmentFactory {
	/**
	 * <item>首页</item> <item>应用</item> <item>游戏</item> <item>专题</item>
	 * <item>推荐</item> <item>分类</item> <item>排行</item>
	 */
	public static final int							FRAGMENT_HOME		= 0;
	public static final int							FRAGMENT_APP		= 1;
	public static final int							FRAGMENT_GAME		= 2;
	public static final int							FRAGMENT_SUBJECT	= 3;
	public static final int							FRAGMENT_RECOMMEND	= 4;
	public static final int							FRAGMENT_CATEGORY	= 5;
	public static final int							FRAGMENT_HOT		= 6;
	public static SparseArrayCompat<BaseFragment>	cacheFragments		= new SparseArrayCompat<BaseFragment>();

	public static BaseFragment getFragment(int postion) {
		BaseFragment fragment = null;

		// if (cacheFragments.containsKey(postion)) {
		// fragment = cacheFragments.get(postion);
		// return fragment;
		// }

		if (cacheFragments.get(postion) != null) {
			fragment = cacheFragments.get(postion);
			return fragment;
		}

//		switch (postion) {
//		case FRAGMENT_HOME:
//			fragment = new HomeFragment();
//			break;
//		case FRAGMENT_APP:
//			fragment = new AppFragment();
//			break;
//		case FRAGMENT_GAME:
//			fragment = new GameFragment();
//			break;
//		case FRAGMENT_SUBJECT:
//			fragment = new SubjectFragment();
//			break;
//		case FRAGMENT_RECOMMEND:
//			fragment = new RecommendFragment();
//			break;
//		case FRAGMENT_CATEGORY:
//			fragment = new CategoryFragment();
//			break;
//		case FRAGMENT_HOT:
//			fragment = new HotFragment();
//			break;
//		default:
//			break;
//		}
		// 进行保存
		cacheFragments.put(postion, fragment);
		return fragment;
	}
}
